package classes
{
	import mx.charts.renderers.DiamondItemRenderer;
	
	public class Layer
	{
		public var label:String;
		public var icon:String;
		public var data:String;
		
		public var visability:Boolean;
        public var stacking_order:int;
        public var sequencing_on_time:int;
        public var sequencing_off_time:int;
        public var opacity:String;    
        
        public var obj_type:String;				//can be line, polygon, ovoid, audio, image
        public var obj_file_location:String;
        public var obj_x_pos:int;
        public var obj_y_pos:int;
        public var obj_height:int = 50;			//given an arbitory height so that we can fing it the first time it is loaded from newb
        public var obj_width:int = 50;
        public var obj_order:int;
        public var obj_scale_factor:int;		//percentage
        public var obj_rotation:int;			//0-360 deg
        public var obj_flip_type:String
        
        public var obj_audio_entry:int;
        public var obj_audio_exit:int;
        public var obj_display_text:String;
        public var obj_original_text:String;
        
 		public var obj_start_x:int;
 		public var obj_start_y:int;
 		public var obj_end_x:int;
 		public var obj_end_y:int;
 		public var obj_stroke_colour:String;
 		public var obj_end_cap:String;
 		public var obj_start_cap:String;
 		public var obj_line_apperance:String;
        public var obj_currentwidth:int;
        public var obj_currentheight:int;
        public var obj_num_points:int;			//four point describes a square/rectangle
        public var obj_colour:uint;				    //defines the line colour
        public var obj_fillcolour:uint;		//defined the filled colour of a polygon/ovoid   
                

		public function SetLine(s_x:int, s_y:int, e_x:int, e_y:int):void{
			this.obj_start_x = s_x;
			this.obj_start_y = s_y;
			
			this.obj_end_x = e_x;
			this.obj_end_y = e_y;
		}
		
		public function SetPolygon(x:int, y:int, b_width:int, b_height:int, points:int):void{
			this.obj_start_x = x;
			this.obj_start_y = y;
			this.obj_currentheight = b_height;;
			this.obj_currentwidth = b_width;

		}
		
		public function SetOvoid(x:int, y:int, b_width:int, b_height:int):void{
			this.obj_start_x = x;
			this.obj_start_y = y;
			this.obj_width = b_width;
			this.obj_height = b_height;
		}
		
		public function SetStroke(colour:uint, e_cap:String, s_cap:String, lineStyle:String):void{
			 this.obj_colour = colour;
			 this.obj_end_cap = e_cap;
			 this.obj_start_cap = s_cap;
			 this.obj_line_apperance = lineStyle;
		}
		
		public function SetFillcolour(fillcolour:uint):void{
			this.obj_fillcolour = fillcolour;
		}
		
		public function SetText(display:String, orig:String):void{
			
			//before adding the text strip the [] if at the beginnig and end of the string
			display = display.substr(1, display.length-2);
			orig = orig.substr(1, orig.length-2);			
			
			 this.obj_display_text = display;
			 this.obj_original_text = orig;
        }
        
        public function SetAudioClipping(entry:int, exit:int):void{
        	this.obj_audio_entry = entry;
			this.obj_audio_exit = exit;
        }
        
        public function SetLayerName(name:String):void{
        	this.label = name;
        }
        
        public function SetVisability(viz:Boolean):void{
        	this.visability = viz;
        }
           
        public function SetObjectProperties(file:String, x:int, y:int):void{
        	this.obj_file_location = file;
        	this.obj_x_pos = x;
        	this.obj_y_pos = y;
        }
        
        public function SetObjectXY(x:int, y:int):void{
        	this.obj_x_pos = x;
        	this.obj_y_pos = y;
        	
        	this.obj_start_x = x;
        	this.obj_start_y = y;
        }
        
        public function setObjectHeightWidth(h:int, w:int):void{
        	this.obj_height = h;
        	this.obj_width = w;
        }
        
        public function SetSequencing(on:int, off:int):void{
        	this.sequencing_on_time = on;
        	this.sequencing_off_time = off;
        }
        
        public function SetStart(on:int):void{
        	this.sequencing_on_time = on;
        }
        
        public function SetDuration(off:int):void{
        	this.sequencing_off_time = off;
        }
        
        public function SetOpacity(opacity:String):void{
        	this.opacity = opacity;
        }
        
        public function SetScale(factor:int):void{
        	this.obj_scale_factor = factor;
        }
		
		public function SetRotation(degrees:int):void{
			this.obj_rotation = degrees;
		}           

        public function SetFlip(orientation:String):void{
        	this.obj_flip_type = orientation;
        }

		public function GetLine():Array{
			var returnArr:Array = new Array;
			returnArr["start_x"] = this.obj_start_x;
			returnArr["start_y"] = this.obj_start_y;
			
			returnArr["end_x"] = this.obj_end_x;
			returnArr["end_y"] = this.obj_end_y;
			
			return returnArr;
		}
		
		public function GetPolygon():Array{

			var returnArr:Array = new Array;
			returnArr["start_x"] = this.obj_start_x;
			returnArr["start_y"] = this.obj_start_y;
			
			returnArr["height"] = this.obj_currentheight;
			returnArr["width"] = this.obj_currentwidth;
			
			return returnArr;

		}
		
		public function GetOvoid():Array{
			
			var returnArr:Array = new Array;
			returnArr["start_x"] = this.obj_start_x;
			returnArr["start_y"] =this.obj_start_y;
			
			returnArr["height"] = this.obj_currentheight;
			returnArr["width"] = this.obj_currentwidth;
			
			return returnArr;
		}
		
		public function GetStroke():Array{
			var returnArr:Array = new Array;
			 returnArr["colour"] = this.obj_colour;
			 returnArr["end_cap"] = this.obj_end_cap;
			 returnArr["start_cap"] = this.obj_start_cap;
			 returnArr["line_style"] = this.obj_line_apperance;
			 
			 return returnArr;
		}
		
		public function GetFillcolour():uint{
			return this.obj_fillcolour;
		}
		
		public function GetText():Array{
			var returnArr:Array = new Array;
			 returnArr["display"] = this.obj_display_text;
			 returnArr["original"] = this.obj_original_text;
			 return returnArr;
        }
        
        public function GetAudioClipping():Array{
        	var returnArr:Array = new Array;
        	returnArr["entry"] = this.obj_audio_entry;
			returnArr["exit"] = this.obj_audio_exit;
			return returnArr;
        }
        
        public function GetLayerName():String{
        	return this.label;
        }
        
        public function GetVisability():Boolean{
        	return this.visability;
        }
           
        public function GetObjectProperties():Array{
        	//create the array to be returned
        	var returnValues:Array = new Array;
        	returnValues["file"] = this.obj_file_location;
        	returnValues["x"] = this.obj_x_pos;
        	returnValues["y"] = this.obj_y_pos; 
        	
        	return returnValues;
        }
        
        public function GetSequencing():Array{
        	var returnArray:Array = new Array;
        	returnArray["on"] = this.sequencing_on_time;
        	returnArray["off"] = this.sequencing_off_time;
        	
        	return returnArray;
        }
        
        public function GetOpacity():String{
        	return this.opacity;
        }
        
        public function GetScale():int{
        	return this.obj_scale_factor;
        }
		
		public function GetRotation():int{
			return this.obj_rotation;
		}           

        public function GetFlip():String{
        	return this.obj_flip_type;
        }
        
        public function GetLayerXML():XML{      	
        	var LayerXML:XML = 
				<layer>
					<name> {this.label} </name>
        
            		<label>{this.label}</label>
            		<icon>{this.icon}</icon>
            		<data>{this.data}</data>
            		<visability>{this.visability}</visability>
            		<stacking_order>{this.stacking_order}</stacking_order>
            			<sequencing>
              				<on_time>{this.sequencing_on_time}</on_time>
              				<off_time>{this.sequencing_off_time}</off_time>
            			</sequencing>
            		<opacity>{this.opacity}</opacity>
            	</layer>;
            	
            var ObjectXML:XML ;
            	
            	
			this.obj_type = this.data.toLowerCase();            		
            //get the object type and determin which section of XML is required
            switch (this.obj_type)
            {
            	case 'audio':
	            	//audio
	            	ObjectXML = <object><object_type>{this.obj_type}
	            	<file_location>{this.obj_file_location}</file_location>
	            	</object_type>
	            	<x_pos>{this.obj_start_x}</x_pos>
			        <y_pos>{this.obj_start_y}</y_pos>
			        <height>{this.obj_height}</height>
			        <width>{this.obj_width}</width>
			        <object_order>{this.obj_order}</object_order>
			        <scale_factor>{this.obj_scale_factor}</scale_factor>
			        <audio_clipping>
			        	<entry_time>{this.obj_audio_entry}</entry_time>
			            <exit_time>{this.obj_audio_exit}</exit_time>
			        </audio_clipping></object>;
			        
			        break;
		         
		         case 'image':     
			        //image
			        ObjectXML = 
	            	<object><object_type>{this.obj_type}
			             <file_location>{this.obj_file_location}</file_location>
			        </object_type>
			        <x_pos>{this.obj_start_x}</x_pos>
			        <y_pos>{this.obj_start_y}</y_pos>
			        <height>{this.obj_height}</height>
			        <width>{this.obj_width}</width>
			        <object_order>{this.obj_order}</object_order>
			        <scale_factor>{this.obj_scale_factor}</scale_factor>
			        <rotation>{this.obj_rotation}</rotation>
			        <flip>{this.obj_flip_type}</flip></object>;
			        
			        break;
			        
			    case 'text':
				     
				    ObjectXML =         
					//text
					<object><object_type>{this.obj_type}</object_type>
			        <x_pos>{this.obj_start_x}</x_pos>
			        <y_pos>{this.obj_start_y}</y_pos>
			        <height>{this.obj_height}</height>
			        <width>{this.obj_width}</width>
			        <object_order>{this.obj_order}</object_order>
			        <display_text>[{this.obj_display_text}]</display_text>
			        <original_text>[{this.obj_original_text}]</original_text></object>;
			      
			        break;
			    case 'line':
		            
		            ObjectXML = 
			        //line
			        <object><object_type>{this.obj_type}</object_type>
	              	<x_pos>{this.obj_start_x}</x_pos>
			        <y_pos>{this.obj_start_y}</y_pos>
			        <height>{this.obj_height}</height>
			        <width>{this.obj_width}</width>
	              	<object_order>{this.obj_order}</object_order>
	              	<line>
	                	<x_start>{this.obj_start_x}</x_start>
	                	<y_start>{this.obj_start_y}</y_start>
	                	<x_end>{this.obj_end_x}</x_end>
	                	<y_end>{this.obj_end_y}</y_end>
	                	<stroke>
	                  		<color>{this.obj_colour}</color>
	                  		<end_cap>{this.obj_end_cap}</end_cap>
	                  		<start_cap>{this.obj_start_cap}</start_cap>
	                  		<line_apperance>{this.obj_line_apperance}</line_apperance>
	                	</stroke>
	              	</line></object>;
	              	
	              	break;
              
              	case 'polygon':
              	
              		ObjectXML = 
	              	//polygon
	              	<object><object_type>{this.obj_type}</object_type>
	              	<x_pos>{this.obj_start_x}</x_pos>
			        <y_pos>{this.obj_start_y}</y_pos>
			        <height>{this.obj_height}</height>
			        <width>{this.obj_width}</width>
	              	<object_order>{this.obj_order}</object_order>
	              	<rotation>{this.obj_rotation}</rotation>
	              	<flip>{this.obj_flip_type}</flip>
	              	<polygon>
		                <x_start>{this.obj_start_x}</x_start>
	                	<y_start>{this.obj_start_y}</y_start>
		                <width>{this.obj_width}</width>
		                <height>{this.obj_height}</height>
		                <number_points>{this.obj_num_points}</number_points>
		                <stroke>
		                  <colour>{this.obj_colour}</colour>
		                  <line_apperance>{this.obj_line_apperance}</line_apperance>
		                </stroke>
		                <fillcolour>{this.obj_fillcolour}</fillcolour>
	              	</polygon></object>;
	              		              	
	              	break;
      				
      			case 'ovoid':
      				
      				ObjectXML = 
	      			//ovoid
	              	<object><object_type>{this.obj_type}</object_type>
	              	<x_pos>{this.obj_start_x}</x_pos>
			        <y_pos>{this.obj_start_y}</y_pos>
			        <height>{this.obj_height}</height>
			        <width>{this.obj_width}</width>
	              	<object_order>{this.obj_order}</object_order>
	                <flip>{this.obj_flip_type}</flip>
	              	<ovoid>
		                <x_start>{this.obj_start_x}</x_start>
	                	<y_start>{this.obj_start_y}</y_start>
		                <width>{this.obj_width}</width>
		                <height>{this.obj_height}</height>
		                <stroke>
		                	<colour>{this.obj_colour}</colour>
		                  	<line_apperance>{this.obj_line_apperance}</line_apperance>
		                </stroke>
		                <fillcolour>{this.obj_fillcolour}</fillcolour>
	              	</ovoid></object>;
	             
	              	break;
          
            }
            
            //now append the object to the layer xml
            LayerXML = LayerXML.appendChild(ObjectXML);
        	return LayerXML;	
        	
        }
        
        public function DisplayXML():XML{
                	
        	var LayerXML:XML = 
				<layer>
            		<label>{this.label}</label>
            		<icon>{this.icon}</icon>
            		<data>{this.data}</data>
            	</layer>;
            	
            return LayerXML;
        }
        
        
        
	}

}